home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Rectangle;
- import java.awt.image.CropImageFilter;
- import java.awt.image.FilteredImageSource;
- import java.awt.image.ImageFilter;
- import java.util.Vector;
-
- public class ImageMap extends Applet {
- Image baseImage;
- ImageMapArea[] areas;
- static final int BRIGHTER = 0;
- static final int DARKER = 1;
- int hlmode;
- int hlpercent = 50;
- private boolean fullrepaint = false;
- private Rectangle repaintrect = new Rectangle();
- private long lastupdate;
- private static final long UPDATERATE = 100L;
- int pressX;
- int pressY;
-
- Image getHighlight(int x, int y, int w, int h) {
- return this.getHighlight(x, y, w, h, this.hlmode, this.hlpercent);
- }
-
- Image getHighlight(int x, int y, int w, int h, int mode, int percent) {
- return this.getHighlight(x, y, w, h, new HighlightFilter(mode == 0, percent));
- }
-
- Image getHighlight(int x, int y, int w, int h, ImageFilter filter) {
- Image cropped = this.makeImage(this.baseImage, new CropImageFilter(x, y, w, h));
- return this.makeImage(cropped, filter);
- }
-
- Image makeImage(Image orig, ImageFilter filter) {
- return ((Component)this).createImage(new FilteredImageSource(orig.getSource(), filter));
- }
-
- void parseHighlight(String s) {
- if (s != null) {
- if (s.startsWith("brighter")) {
- this.hlmode = 0;
- if (s.length() > "brighter".length()) {
- this.hlpercent = Integer.parseInt(s.substring("brighter".length()));
- return;
- }
- } else if (s.startsWith("darker")) {
- this.hlmode = 1;
- if (s.length() > "darker".length()) {
- this.hlpercent = Integer.parseInt(s.substring("darker".length()));
- }
- }
-
- }
- }
-
- public void init() {
- this.parseHighlight(((Applet)this).getParameter("highlight"));
- this.baseImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), ((Applet)this).getParameter("img"));
- Vector areaVec = new Vector();
- int var3 = 1;
-
- while(true) {
- String s = ((Applet)this).getParameter("area" + var3);
- ImageMapArea newArea;
- if (s == null) {
- s = ((Applet)this).getParameter("rect" + var3);
- if (s == null) {
- break;
- }
-
- String url = ((Applet)this).getParameter("href" + var3);
- if (url != null) {
- s = s + "," + url;
- }
-
- newArea = new HrefArea();
- } else {
- int classend = s.indexOf(",");
-
- try {
- String name = s.substring(0, classend);
- newArea = (ImageMapArea)Class.forName(name).newInstance();
- } catch (Exception e) {
- ((Throwable)e).printStackTrace();
- break;
- }
-
- s = s.substring(classend + 1);
- }
-
- newArea.init(this, s);
- areaVec.addElement(newArea);
- ++var3;
- }
-
- this.areas = new ImageMapArea[areaVec.size()];
- areaVec.copyInto(this.areas);
- this.checkSize();
- }
-
- synchronized void checkSize() {
- int w = this.baseImage.getWidth(this);
- int h = this.baseImage.getHeight(this);
- if (w > 0 && h > 0) {
- ((Component)this).resize(w, h);
- this.repaintrect.x = this.repaintrect.y = 0;
- this.repaintrect.width = w;
- this.repaintrect.height = h;
- this.fullrepaint = true;
- ((Component)this).repaint();
- }
-
- }
-
- public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
- if ((infoflags & 3) != 0) {
- this.checkSize();
- }
-
- if ((infoflags & 56) != 0) {
- ((Component)this).repaint((infoflags & 48) != 0 ? 0L : 100L, x, y, width, height);
- }
-
- return (infoflags & 96) == 0;
- }
-
- public void paint(Graphics g) {
- synchronized(this){}
-
- try {
- if (this.fullrepaint) {
- g = g.create();
- g.clipRect(this.repaintrect.x, this.repaintrect.y, this.repaintrect.width, this.repaintrect.height);
- this.fullrepaint = false;
- }
- } catch (Throwable var4) {
- throw var4;
- }
-
- if (this.baseImage != null) {
- g.drawImage(this.baseImage, 0, 0, this);
- if (this.areas != null) {
- int i = this.areas.length;
-
- while(true) {
- --i;
- if (i < 0) {
- break;
- }
-
- if (this.areas[i].active || this.areas[i].entered) {
- this.areas[i].setState(g, this.areas[i].entered);
- }
- }
- }
-
- }
- }
-
- public void update(Graphics g) {
- if (this.fullrepaint) {
- this.paint(g);
- } else if (this.baseImage != null) {
- g.drawImage(this.baseImage, 0, 0, this);
- if (this.areas != null) {
- int i = this.areas.length;
-
- while(true) {
- --i;
- if (i < 0) {
- int i = this.areas.length;
-
- while(true) {
- --i;
- if (i < 0) {
- return;
- }
-
- if (this.areas[i].entered) {
- this.areas[i].setState(g, true);
- }
- }
- }
-
- if (this.areas[i].active && !this.areas[i].entered) {
- this.areas[i].setState(g, false);
- }
- }
- }
- }
- }
-
- public void mouseExit() {
- boolean changed = false;
-
- for(int i = 0; i < this.areas.length; ++i) {
- if (this.areas[i].active) {
- this.areas[i].entered = false;
- changed = true;
- }
- }
-
- if (changed) {
- ((Component)this).repaint();
- }
-
- }
-
- public boolean mouseMove(Event evt, int x, int y) {
- boolean changed = false;
- boolean propagate = true;
-
- for(int i = 0; i < this.areas.length; ++i) {
- if (this.areas[i].inside(x, y)) {
- this.areas[i].entered = propagate;
- if (this.areas[i].terminal) {
- propagate = false;
- }
- } else {
- this.areas[i].entered = false;
- }
-
- if (this.areas[i].active != this.areas[i].entered) {
- changed = true;
- }
- }
-
- if (changed) {
- ((Component)this).repaint();
- }
-
- return true;
- }
-
- public boolean mouseDown(Event evt, int x, int y) {
- this.pressX = x;
- this.pressY = y;
-
- for(int i = 0; i < this.areas.length; ++i) {
- if (this.areas[i].inside(x, y)) {
- this.areas[i].press(x, y);
- if (this.areas[i].terminal) {
- break;
- }
- }
- }
-
- return true;
- }
-
- public boolean mouseUp(Event evt, int x, int y) {
- for(int i = 0; i < this.areas.length; ++i) {
- if (this.areas[i].inside(this.pressX, this.pressY)) {
- this.areas[i].lift(x, y);
- if (this.areas[i].terminal) {
- break;
- }
- }
- }
-
- return true;
- }
-
- public boolean mouseDrag(Event evt, int x, int y) {
- this.mouseMove(evt, x, y);
-
- for(int i = 0; i < this.areas.length; ++i) {
- if (this.areas[i].inside(this.pressX, this.pressY)) {
- this.areas[i].drag(x, y);
- if (this.areas[i].terminal) {
- break;
- }
- }
- }
-
- return true;
- }
- }
-